﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace StandUp
{
    public partial class AddEvent : Form
    {
        public AddEvent(int id)
        {
            InitializeComponent();
            if (id != -1)
            {
                ModelEvent = Mybll.GetEventByID(id, "-1");
                tb_title.Text=ModelEvent.EventTitle;
                tb_mark.Text=ModelEvent.EventMark;
                tb_relate.Text=ModelEvent.EventRelate;
                tb_location.Text=ModelEvent.EventLocation;
                dtp_stime.Value=ModelEvent.Startime;
                dtp_etime.Value=ModelEvent.Endtime;
                //ModelEvent.State = "未开始";
                //ModelEvent.Addtime = DateTime.Now;
                tb_ahead.Text=ModelEvent.AheadMin.ToString();
                cb_duplicate.SelectedItem=ModelEvent.Duplicate;
                ckb_allday.Checked=ModelEvent.AllDayEvent;
            }
        }
       private void AddEvent_Load(object sender, EventArgs e)
        {
            cb_duplicate.SelectedIndex = 0;
        }
        private void btn_GetMap_Click(object sender, EventArgs e)
        {
            Map map = new Map();
            map.Show();
        }
        Dictionary<string, string> duplicate = new Dictionary<string, string> { {"不是重复事件",""},{ "每天", "day" }, { "每周", "week" }, { "每月", "month" }, { "每年", "year" } };
        AssData.EventModel ModelEvent = new AssData.EventModel();
        AssData.DataSelect Mybll = new AssData.DataSelect();
        private void btn_OK_Click(object sender, EventArgs e)
        {            
            ModelEvent.EventTitle = tb_title.Text;
            ModelEvent.EventMark = tb_mark.Text;
            ModelEvent.EventRelate = tb_relate.Text;
            ModelEvent.EventLocation = tb_location.Text;
            ModelEvent.Startime = dtp_stime.Value;
            ModelEvent.Endtime = dtp_etime.Value;
            ModelEvent.State = "未开始";
            ModelEvent.Addtime = DateTime.Now;
            ModelEvent.AheadMin = int.Parse(tb_ahead.Text);
            ModelEvent.Duplicate =duplicate[cb_duplicate.SelectedItem.ToString()];
            ModelEvent.AllDayEvent = ckb_allday.Checked;
            if (Mybll.InsertEvent(ModelEvent))
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
                MessageBox.Show("日程新建失败！");
        }

        private void AddEvent_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Dispose(true);
        }

        private void btn_close_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
